<template>
  <el-dialog v-model="visible" :title="!dataForm.id ? '新增' : '修改'" :close-on-click-modal="false" :close-on-press-escape="false">
    <el-form :model="dataForm" :rules="rules" ref="dataFormRef" @keyup.enter="dataFormSubmitHandle()" label-width="120px">
          <el-form-item label="注册用户id" prop="userId">
        <el-input v-model="dataForm.userId" placeholder="注册用户id"></el-input>
      </el-form-item>
          <el-form-item label="用户姓名" prop="realName">
        <el-input v-model="dataForm.realName" placeholder="用户姓名"></el-input>
      </el-form-item>
          <el-form-item label="身份证" prop="idCard">
        <el-input v-model="dataForm.idCard" placeholder="身份证"></el-input>
      </el-form-item>
          <el-form-item label="卡号" prop="payCard">
        <el-input v-model="dataForm.payCard" placeholder="卡号"></el-input>
      </el-form-item>
          <el-form-item label="银行名称" prop="bankName">
        <el-input v-model="dataForm.bankName" placeholder="银行名称"></el-input>
      </el-form-item>
          <el-form-item label="金额 交易" prop="balance">
        <el-input v-model="dataForm.balance" placeholder="金额 交易"></el-input>
      </el-form-item>
          <el-form-item label="公司id" prop="companyId">
        <el-input v-model="dataForm.companyId" placeholder="公司id"></el-input>
      </el-form-item>
          <el-form-item label="公司名称" prop="companyName">
        <el-input v-model="dataForm.companyName" placeholder="公司名称"></el-input>
      </el-form-item>
          <el-form-item label="转帐流水" prop="recordNo">
        <el-input v-model="dataForm.recordNo" placeholder="转帐流水"></el-input>
      </el-form-item>
          <el-form-item label="类型 1收入 2支出 " prop="type">
        <el-input v-model="dataForm.type" placeholder="类型 1收入 2支出 "></el-input>
      </el-form-item>
          <el-form-item label="交易类型：1 工资  2 转账   3 借款    4提现    借款和提现都需要审核通过" prop="recordType">
        <el-input v-model="dataForm.recordType" placeholder="交易类型：1 工资  2 转账   3 借款    4提现    借款和提现都需要审核通过"></el-input>
      </el-form-item>
          <el-form-item label="交易渠道 1  银行卡 2 微信    3其他" prop="recordChannel">
        <el-input v-model="dataForm.recordChannel" placeholder="交易渠道 1  银行卡 2 微信    3其他"></el-input>
      </el-form-item>
          <el-form-item label="交易时间" prop="recordTime">
        <el-input v-model="dataForm.recordTime" placeholder="交易时间"></el-input>
      </el-form-item>
          <el-form-item label="转账截图" prop="recordImg">
        <el-input v-model="dataForm.recordImg" placeholder="转账截图"></el-input>
      </el-form-item>
          <el-form-item label="1 审核中 2 拒绝 3 通过" prop="isPass">
        <el-input v-model="dataForm.isPass" placeholder="1 审核中 2 拒绝 3 通过"></el-input>
      </el-form-item>
          <el-form-item label="创建时间" prop="createTime">
        <el-input v-model="dataForm.createTime" placeholder="创建时间"></el-input>
      </el-form-item>
          <el-form-item label="更新时间" prop="updateTime">
        <el-input v-model="dataForm.updateTime" placeholder="更新时间"></el-input>
      </el-form-item>
      </el-form>
    <template #footer>
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmitHandle()">确定</el-button>
    </template>
  </el-dialog>
</template>

<script lang="ts" setup>
import { reactive, ref } from "vue";
import baseService from "@/service/baseService";
import { ElMessage } from "element-plus";
const emit = defineEmits(["refreshDataList"]);

const visible = ref(false);
const dataFormRef = ref();

const dataForm = reactive({
  id: '',  userId: '',  realName: '',  idCard: '',  payCard: '',  bankName: '',  balance: '',  companyId: '',  companyName: '',  recordNo: '',  type: '',  recordType: '',  recordChannel: '',  recordTime: '',  recordImg: '',  isPass: '',  createTime: '',  updateTime: ''});

const rules = ref({
          userId: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ],
          realName: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ],
          idCard: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ],
          payCard: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ],
          bankName: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ],
          balance: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ],
          companyId: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ],
          companyName: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ],
          recordNo: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ],
          type: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ],
          recordType: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ],
          recordChannel: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ],
          recordTime: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ],
          recordImg: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ],
          isPass: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ],
          createTime: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ],
          updateTime: [
      { required: true, message: '必填项不能为空', trigger: 'blur' }
    ]
  });

const init = (id?: number) => {
  visible.value = true;
  dataForm.id = "";

  // 重置表单数据
  if (dataFormRef.value) {
    dataFormRef.value.resetFields();
  }

  if (id) {
    getInfo(id);
  }
};

// 获取信息
const getInfo = (id: number) => {
  baseService.get("/api/userbalancelog/" + id).then((res) => {
    Object.assign(dataForm, res.data);
  });
};

// 表单提交
const dataFormSubmitHandle = () => {
  dataFormRef.value.validate((valid: boolean) => {
    if (!valid) {
      return false;
    }
    (!dataForm.id ? baseService.post : baseService.put)("/api/userbalancelog", dataForm).then((res) => {
      ElMessage.success({
        message: '成功',
        duration: 500,
        onClose: () => {
          visible.value = false;
          emit("refreshDataList");
        }
      });
    });
  });
};

defineExpose({
  init
});
</script>
